# TODO:
# As of right now, this Makefile is far from complete.
#

# -------------------------------------
# Paths
# -------------------------------------
DIR_UTILS = $(CURDIR)/../../utils


# -------------------------------------
# Compilers, utilities and flags:
# -------------------------------------

# TODO: will add support for system other than POSIX should any one needs that
SHELL	= /bin/sh
RM	= rm -f
RENAME	= mv
# LaTeX -> PDF
XETEX	= xelatex
XETEX_FLAGS = -halt-on-error
# stix -> TeX converter (stix stands for Simple Typesetting In XML)
SDC	= ${DIR_UTILS}/sdc

# -------------------------------------
# Sources:
# -------------------------------------
SRC_INC = \
	  header.tex \
	  footer.tex \
	  style.tex \
	  xCJKnumb.sty \
	  zhconfig.tex

SRC_COMMON = \
	  preface.tex \
	  toc.tex \
	  appendix.tex \
	  index.tex

SRC_ALL_CHAPTERS	= \
		  chapter01.tex \
		  chapter02.tex \
		  chapter03.tex \
		  chapter04.tex \
		  chapter05.tex \
		  chapter06.tex \
		  chapter07.tex \
		  chapter08.tex \
		  chapter09.tex \
		  chapter10.tex \
		  chapter11.tex \
		  chapter12.tex 

SRC_PDF_BOOK 	= ${SRC_INC} ${SRC_COMMON} ${SRC_ALL_CHAPTERS} book.tex 
SRC_HTML	= ${SRC_COMMON}

# -------------------------------------
# Outputs:
# -------------------------------------
# .pdf
PDF_BOOK	= book.pdf
PDF_CHAPTERS	= \
		  chapter01.pdf \
		  chapter02.pdf \
		  chapter03.pdf \
		  chapter04.pdf \
		  chapter05.pdf \
		  chapter06.pdf \
		  chapter07.pdf \
		  chapter08.pdf \
		  chapter09.pdf \
		  chapter10.pdf \
		  chapter11.pdf \
		  chapter12.pdf


# -------------------------------------
# Pattern Rules that make life easier
# -------------------------------------
%.pdf : %.tex ${SRC_INC}
	${XETEX} ${XETEX_FLAGS} $<
	#${XETEX} ${XETEX_FLAGS} $<
%.tex : %.xml
	${SDC} $< $@


# -------------------------------------
# Targets:
# -------------------------------------
# Output Formats:
.PHONY : pdf pdf-chapters html

# Actions:
.PHONY : all clean

default : pdf
all : pdf pdf-chapters html

clean :
	${RM} *.log *.aux *.out *~

pdf : ${PDF_BOOK}

pdf-chapters : ${PDF_CHAPTERS}

html : ${SRC_HTML}

${PDF_BOOK} : ${SRC_PDF_BOOK}

